# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=gnu-efi
pkgver=3.0.17
pkgrel=3
pkgdesc="Develop EFI applications using the GNU toolchain and the EFI development environment"
arch=(loong64 x86_64)
url="https://sourceforge.net/projects/gnu-efi/"
license=(BSD)
conflicts=(gnu-efi-libs)
provides=(gnu-efi-libs)
replaces=(gnu-efi-libs)
source=(https://download.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.bz2
        "gnu-efi-3.0.17-la64.patch")
options=(!lto !strip)
sha512sums=('0893ca234272584f889b1ae1c75341a9ceee60acfd32765daa5d704191ba00450536a287b949304c6d055d1bf125cc29e24fc41df8e5230e0da4f9d944876512'
            'cbeb446d4e3f3b7169b798c8014aedc30e5bc3d576856ebd69af7d9ee5277f99e16709687b1140c2eac3a2edddce49aa4a5d4d91a0e1ce408c3b7fe134a57ca7')
b2sums=('27f8171b411a6a8a138d44d91c7e4e4291aa399562825d51a398913572119482ffeb303d7508ae13eacd2cd10b8f5098405ab16eb56243587efe93235f661285'
        '429d8a968edc6deb5e73a4faabb523dfb490a173d7c48a9270e1ccd5758d0262e9eb39bb47056375f07bd3f8ff7a4d83a3977565538d5e039652e9672220e9b1')

prepare() {
  # -Werror, not even once
  sed -e 's/-Werror//g' -i $pkgname-$pkgver/Make.defaults
  patch -d $pkgname-$pkgver -Np1 -i "../gnu-efi-3.0.17-la64.patch"
}

build() {
  cd $pkgname-$pkgver
  # NOTE: apply only minimal CFLAGS, as gnu-efi does not provide userspace
  # libs, but may be used in unitialized machine state and should therefore not
  # be architecture optmized
  CFLAGS="-O2"
  # upstream provides LDFLAGS directly to ld: https://sourceforge.net/p/gnu-efi/bugs/33/
  LDFLAGS="${LDFLAGS//-Wl/}"
  LDFLAGS="${LDFLAGS//,/ }"
  make
}

package() {
  cd $pkgname-$pkgver
  make INSTALLROOT="$pkgdir" PREFIX=/usr install
  install -vDm 644 README.efilib -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {ChangeLog,README.{gnuefi,git,elilo}} -t "$pkgdir/usr/share/doc/$pkgname/"
}
